package Search;

import java.io.File;
import java.util.Date;

import DataTags.DataTagsAdapter;
import DataTags.DataTagsAdapterDB;
import DataTags.DataTagsToFiles;
import junit.framework.TestCase;
/**
 * this  is a junit test class for the search class
 * @author oz
 *
 */
public class testSearch extends TestCase {
	DataTagsToFiles myTags=new DataTagsToFiles();
	DataTagsAdapter myData=new DataTagsAdapterDB(myTags);
	Search mySearch=new Search(myData);
	public void testing(){
		File f = new File("");
        String go=new String(f.getAbsolutePath());
        System.out.println(go);
		String path=new String(go+"/logics/");//obviously on different computer the path to this file is different
		//and you need to change it.
		File fi=new File(path+"ClasifyByMdate.class");
		Date d=new Date(fi.lastModified());
		String last_m=new String(d.toGMTString());
		String []tags="logics@mDate@".split("@");
		myData.addTagsTo(fi.getName(), last_m,fi.getPath(), tags);
		assertTrue(mySearch.getAllFiles().length >0);//the db contains some files and the search can return them
		assertTrue(mySearch.getAllTags().length>0);
		
		String tag =mySearch.searchThis("ClasifyByMdate.class", true);//search for the tags of file "about.html" that I inserted previously to the DB
		//assertTrue(tags.compareTo("jsp@")==0);//it worked - I previously
		//tagged this file with these tags
		// It won't work  when the file doesn't have these tags
		mySearch.searchThis("ClasifyByMdate.class", true);//second time- this time the returned tags are in the search cache
		//- so the search need now prints to the console - "tags in cache"- I saw it printed .
		
	}
	
}
